"""
@author RansySun
@create 2019-12-03-22:42
"""
from .celery import app
from home.models import Banner

from django.conf import settings
from django.core.cache import cache
from home.serializers import BannerModelSerializer


@app.task
def update_banner_cache():
    banner_query = Banner.objects.filter(is_delete=False, is_show=True).order_by("-order")[:settings.BANNER_COUNT]

    banner_list = BannerModelSerializer(banner_query, many=True).data

    cache.set("banner_list", banner_list)
